package com.example.wan_android.viewmodel

import android.content.Intent
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.wan_android.ui.activity.MainActivity
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class LaunchViewModel : BaseViewModel() {
    val progress = MutableLiveData<Int>(0)

    fun simulateLoading() {
        viewModelScope.launch {
            while (progress.value!! < 100) {
                delay(50)
                progress.value = progress.value!! + 5
            }
            jumpMainActivityWithFinish()
        }
    }

    private fun jumpMainActivityWithFinish() {
        startActivity(
            targetIntent = Intent(),
            targetClass = MainActivity::class.java,
            finishCurrent = true // 关键参数
        )
    }

}